﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WStest.Models;

namespace WStest.Controllers
{
    public class FriendController : Controller
    {
        Service service = new Service();

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ListUsers(UserView u)
        {
            return View(service.FindUsers(u.Username));
        }

        public ActionResult ListFriends()
        {
            UserView u = service.GetUserByUsername(User.Identity.Name);
            List<UserView> f = service.GetFriendsByUserId(u.Id);
            return View(f);
        }

        public ActionResult AddFriend(int id)
        {
            UserView u = service.GetUserByUsername(User.Identity.Name);
            service.MakeFriend(u.Id, id);
            return View();
        } 

        public ActionResult Delete(int id)
        {
            UserView u = service.GetUserByUsername(User.Identity.Name);
            service.RemoveFriend(u.Id, id);
            return RedirectToAction("ListFriends");
        }

    }
}
